<template>
  <div class="main-body">
    <!-- 头部搜索 -->
    <div class="demo-form-inline">
      <el-form :inline="true">
        <el-form-item label="设备编号">
          <el-input v-model="input" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            class="search"
            @click="searchEquip"
          >查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="main-form">
      <el-table :data="articles" stripe border style="margin-top: 30px">
        <el-table-column type="index" label="序号" width="60px" />
        <el-table-column prop="innerCode" label="设备编号" />
        <el-table-column prop="type.name" label="设备型号" />
        <el-table-column prop="node.name" label="详细地址" />
        <el-table-column prop="vmStatus1" label="运营状态" />
        <el-table-column prop="vmStatus1" label="设备状态" />
        <el-table-column label="操作" width="150px" align="center">
          <template #default="scope">
            <el-button
              type="text"
              @click="lookNews(scope.row)"
            >查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div class="main-foot">
        <span>共{{ totalCount }}条记录--第{{ params.pageIndex }}/{{
          totalPage
        }}页</span>
        <el-button-group>
          <el-button
            type="primary"
            icon="el-icon-arrow-left"
            @click="changePageIndex1"
          >上一页</el-button>
          <el-button type="primary" @click="changePageIndex2">
            下一页<i class="el-icon-arrow-right" />
          </el-button>
        </el-button-group>
      </div>
    </div>
    <el-dialog title="设备详情" :visible.sync="dialogVisible" width="700px">
      <div class="headerBar">
        <span>销售量：{{ salesMuch }}</span>
        <span>销售额：{{ salesMoney / 100 }}</span>
        <span>补货次数：{{ replenishmentMuch }}</span>
        <span>维修次数：{{ maintenanceMuch }}</span>
      </div>
      <div class="goodslist">
        <div v-for="(item, index) in shopList" :key="index" class="goodsBox">
          <span class="skuName">{{ item.skuName }}</span><span class="skuCount">: {{ item.count }}</span>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getEquipSearch,
  getSales,
  moneySales,
  replenishment,
  maintenance,
  shopSales
} from '@/api/equipment/condition'
export default {
  name: 'ConditionPage',
  components: {},
  props: {},
  data() {
    return {
      input: '',
      articles: [],
      totalCount: '', // 记录的数量
      totalPage: '',
      params: {
        pageIndex: 1,
        pageSize: 10
      },
      dialogVisible: false,
      salesMoney: '',
      salesMuch: '',
      replenishmentMuch: '',
      maintenanceMuch: '',
      shopList: []
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getEquipSearch()
  },
  methods: {
    async getEquipSearch() {
      const res = await getEquipSearch(this.params)
      // console.log(res)
      this.totalCount = res.totalCount
      this.totalPage = res.totalPage
      const arr = res.currentPageRecords
      arr.forEach((item) => {
        if (item.vmStatus === 0) {
          item.vmStatus1 = '未投放'
        } else if (item.vmStatus === 1) {
          item.vmStatus1 = '运营'
        } else if (item.vmStatus === 3) {
          item.vmStatus1 = '撤机'
        }
        this.articles = arr
      })
    },
    // 页面减一
    changePageIndex1() {
      if (this.params.pageIndex > 1) {
        this.params.pageIndex = this.params.pageIndex - 1
      }
      this.getEquipSearch()
    },
    // 页面加一
    changePageIndex2() {
      if (this.params.pageIndex < this.totalPage) {
        this.params.pageIndex = this.params.pageIndex + 1
      }
      this.getEquipSearch()
    },
    // 查询
    async searchEquip() {
      this.params.innerCode = this.input
      const res = await getEquipSearch(this.params)
      // console.log(res)
      this.totalCount = res.totalCount
      this.totalPage = res.totalPage
      const arr = res.currentPageRecords
      console.log(arr)
      arr.forEach((item) => {
        if (item.vmStatus === 0) {
          item.vmStatus1 = '未投放'
        } else if (item.vmStatus === 1) {
          item.vmStatus1 = '运营'
        } else if (item.vmStatus === 3) {
          item.vmStatus1 = '撤机'
        }
        this.articles = arr
      })
    },
    async lookNews(row) {
      this.dialogVisible = true
      console.log(row)
      const params = {}
      params.start = '2022-11-01 00:00:00'
      params.end = '2022-11-16 23:59:59'
      const starts = '2022-11-01'
      const ends = '2022-11-16'
      params.innerCode = row.innerCode
      const res = await getSales(params)
      const res1 = await moneySales(params)
      const res2 = await replenishment(row.innerCode, starts, ends)
      const res3 = await maintenance(row.innerCode, starts, ends)
      const res4 = await shopSales(row.innerCode, starts, ends)
      console.log(res, res1, res2, res3, res4)
      this.salesMoney = res1
      this.salesMuch = res
      this.replenishmentMuch = res2
      this.maintenanceMuch = res3
      this.shopList = res4
    }
  }
}
</script>

<style scoped lang="scss">
.main-body {
  background-color: #f8fafd;
  .demo-form-inline {
    background-color: #fff;
    line-height: 64px;
    height: 64px;
    .search {
      height: 36px;
    }
  }
  .main-form {
    background-color: #fff;
    margin-top: 20px;
  }
  .main-foot {
    margin-top: 20px;
    height: 36px;
    display: flex;
    justify-content: space-between;
    span {
      line-height: 36px;
      font-size: 14px;
    }
    ::v-deep .el-button-group > .el-button:first-child {
      height: 36px;
    }
    ::v-deep .el-button-group > .el-button:last-child {
      height: 36px;
    }
  }
}
::v-deep .el-form--inline .el-form-item__content {
  display: inline-block;
  line-height: 64px;
  vertical-align: top;
}

.headerBar {
  width: 600px;
  display: flex;
  justify-content: space-around;
  font-size: 16px;
  color: #999;
}

.goodslist {
  margin-top: 30px;
  width: 600px;
  display: flex;
  flex-wrap: wrap;
  .goodsBox {
    width: 150px;
    border: 1px solid black;
    font-size: 14px;
    color: #000;
    font-weight: normal;
  }
}
</style>
